﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Waiter.Common;
using Waiter.ServiceReference1;
using Waiter.UserControls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Item Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234232

namespace Waiter
{
    /// <summary>
    /// A page that displays details for a single item within a group while allowing gestures to
    /// flip through other items belonging to the same group.
    /// </summary>
    public sealed partial class GiaoDienBan : Page
    {
        private NavigationHelper navigationHelper;
        private ObservableDictionary defaultViewModel = new ObservableDictionary();
        private Table table = null;

        /// <summary>
        /// This can be changed to a strongly typed view model.
        /// </summary>
        public ObservableDictionary DefaultViewModel
        {
            get { return this.defaultViewModel; }
        }

        /// <summary>
        /// NavigationHelper is used on each page to aid in navigation and 
        /// process lifetime management
        /// </summary>
        public NavigationHelper NavigationHelper
        {
            get { return this.navigationHelper; }
        }

        public GiaoDienBan()
        {
            this.InitializeComponent();
            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += navigationHelper_LoadState;
            init();
        }

        private void init()
        {
            GoiMonControl goimonControl = new GoiMonControl();
            this.contentRegion.Children.Clear();
            this.contentRegion.Children.Add(goimonControl);

        }

        private async void init2() 
        {
            SoLuongDialog slDialog = new SoLuongDialog("BÀN TRONG GÓC", "Công chúa non nấu cháo");
            slDialog.CloseRequested += slDialog_CloseRequested;
            slDialog.OkRequested += slDialog_OkRequested;
            this.SoLuongPopup.Child = slDialog;
            SoLuongPopup.IsOpen = true;
        }

        void slDialog_OkRequested(object sender, EventArgs e)
        {
            // Dismiss the dialog
            if (SoLuongPopup.IsOpen)
            {
                SoLuongPopup.IsOpen = false;
            }
            int ret = (e as NumberEventArgs).number;
        }

        void slDialog_CloseRequested(object sender, EventArgs e)
        {
            if (SoLuongPopup.IsOpen)
            {
                SoLuongPopup.IsOpen = false;
            }
        }



        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            object navigationParameter;
            if (e.PageState != null && e.PageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = e.PageState["SelectedItem"];
                table = navigationParameter as Table;
            }

        }

        #region NavigationHelper registration

        /// The methods provided in this section are simply used to allow
        /// NavigationHelper to respond to the page's navigation methods.
        /// 
        /// Page specific logic should be placed in event handlers for the  
        /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
        /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
        /// The navigation parameter is available in the LoadState method 
        /// in addition to page state preserved during an earlier session.

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            navigationHelper.OnNavigatedTo(e);
            table = e.Parameter as Table;
            init();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            navigationHelper.OnNavigatedFrom(e);

        }

        #endregion

        private void ChonMonAppBarButton_Tapped(object sender, TappedRoutedEventArgs e)
        {

        }

        private void HoaDonAppBarButton_Tapped(object sender, TappedRoutedEventArgs e)
        {

        }
    }
}
